package com.vitabuybuy.tv.ui.mine.wallet.viewmodel

import androidx.lifecycle.MutableLiveData
import com.library.common.base.BaseViewModel
import com.vitabuybuy.tv.BR
import com.vitabuybuy.tv.R
import com.vitabuybuy.tv.dto.BillListDto
import com.library.common.base.MessageModel
import com.library.common.ext.rxHttpRequest
import com.library.common.net.error.msg
import com.library.common.toast.XToast
import com.vitabuybuy.tv.network.WalletRepository
import me.tatarka.bindingcollectionadapter2.ItemBinding
import me.tatarka.bindingcollectionadapter2.OnItemBind

class MyWalletViewModel : BaseViewModel() {

    val bankcards = ArrayList<String>()

    //网格布局的adapter绑定
    val bankCardBinding: OnItemBind<String> =
        OnItemBind { itemBinding: ItemBinding<Any>, position: Int, item: String ->
            itemBinding.set(BR.itemBean, R.layout.item_bank_card).bindExtra(BR.position, position)
        }

    val myWallet = MutableLiveData<Double>()

    fun getMyWallet() {
        rxHttpRequest {
            onRequest = {
                myWallet.value =  WalletRepository.getMyWallet().await()
            }
            onError = {
                XToast.normal(it.msg)
            }
            isShowDialogRequest = true
        }
    }

    val billList = MutableLiveData<MutableList<BillListDto>>()

    fun getBillList(
        type: String,
        pageNumber: Int
    ) {
        rxHttpRequest {
            onRequest = {
                val it =  WalletRepository.getBillList(type,pageNumber, 10) .await()
                billList.value = it
                defUI.msgEvent.postValue(MessageModel(1,arg1 = it.size))
            }
            onError = {
                XToast.normal(it.msg)
            }
            isLoadingType = true
            isRefresh = pageNumber == 1
        }
    }


    fun getDataList() {
        bankcards.add("")
        bankcards.add("")
        bankcards.add("")
        bankcards.add("")
    }
}
